#######################################################################
#                       Point cloud declaration                       #
#######################################################################

snippet cloud "Point cloud" !b
pcl::PointCloud<${2:pcl::PointXYZ}> ${1:cloud}$0
endsnippet

snippet cloudp "Point cloud pointer" !b
pcl::PointCloud<${2:pcl::PointXYZ}>::Ptr ${1:cloud}(new pcl::PointCloud<$2>)$0
endsnippet

#######################################################################
#                                 I/O                                 #
#######################################################################

snippet load "Load point cloud" !b
if (pcl::io::loadPCDFile${3/.+/</}${3:pcl::PointXYZ}${3/.+/>/}(${2:filename}, ${1:*cloud}) == -1)
{
  PCL_ERROR("Couldn't read file %s\n", $2);
  return -1;
}$0
endsnippet

#######################################################################
#                          Console arguments                          #
#######################################################################

snippet arg "Parse argument" !b
${3:float} $2 = ${4:0.0f};
pcl::console::parse (argc, argv, "${1:--name}", ${2:variable});$0
endsnippet

snippet argb "Parse boolean argument" !b
bool ${2:flag} = pcl::console::find_switch (argc, argv, "${1:--name}");$0
endsnippet

#######################################################################
#                           Console output                            #
#######################################################################

global !p
def get_level(c):
  levels = ["debug", "info", "warn", "error", "highlight", "value"]
  for l in levels:
    if l.lower().startswith(c.lower()):
      return l
  return "info"
endglobal

snippet "print(\w?)" "Print message" br
pcl::console::print_`!p
snip.rv = get_level(match.group(1) or 'i')
` ("${1:Message}"${2/.+/, /}${2}${2/.+//});$0
endsnippet

#######################################################################
#                             Boost graph                             #
#######################################################################

snippet fore "Iterate over graph edges" !b
for (const auto& ${2:edge} : as_range (boost::edges (${1:graph})))
{
  $0
}
endsnippet

snippet foroe "Iterate over out edges of a vertex" !b
for (const auto& ${3:edge} : as_range (boost::out_edges (${1:vertex}, ${2:graph})))
{
  $0
}
endsnippet

snippet forav "Iterate over adjacent vertices of a vertex" !b
for (const auto& ${3:neighbor} : as_range (boost::adjacent_vertices (${1:vertex}, ${2:graph})))
{
  $0
}
endsnippet

snippet forv "Iterate over graph vertices" !b
for (const auto& ${2:vertex} : as_range (boost::vertices (${1:graph})))
{
  $0
}
endsnippet

snippet est "Edge source and target" !b
${3:auto} src = boost::source (${1:edge}, ${2:graph});
$3 tgt = boost::target ($1, $2);$0
endsnippet

snippet nv "Number of vertices" w
boost::num_vertices (${1:graph})$0
endsnippet

snippet ne "Number of edges" w
boost::num_edges (${1:graph})$0
endsnippet

snippet get "Boost get" w
boost::get (boost::${1:edge_weight}, ${2:graph}${3/.+/, /}${3:${1/([^_]+).*/$1/}}${3/.+//})$0
endsnippet

snippet put "Boost put" w
boost::put (boost::${1:edge_weight}, ${2:graph}, ${3:${1/([^_]+).*/$1/}}, ${4:value})$0
endsnippet

